package NM;

import java.util.Arrays;

public class MyStack {
    public int[] elem;
    public int usedSize;

    public MyStack(int[] elem) {
        this.elem =new int[10];
    }
    public void push(int val){
        if(isfull()){
            this.elem= Arrays.copyOf(elem,2*elem.length);
        }
        elem[usedSize++]=val;
    }
    public boolean isfull(){
        return usedSize== elem.length;
    }
    //删除栈上元素；
    public int pop(){
        if(isEmpty()){
            throw new EmptyStackException();
        }
        int val=elem[usedSize-1];
        usedSize--;
        return val;
    }
    public boolean isEmpty(){
        return usedSize==0;
    }
    //获取栈顶元素，但是不删除；
    public int peek(){
        if(isEmpty()){
            throw new EmptyStackException();
        }
        return elem[usedSize-1];
    }

}
